package com.suoluo.zenadmin.http.weixin;

import com.suoluo.zenadmin.http.Http;
import com.suoluo.zenadmin.http.HttpResponse;

public class WXHttp {

	private static String appId = "wxdd5380e8c2961eea";
	private static String secret = "8776c1d9bea497dad4027eb27530e34a";
	
	
	private WXHttp(){
	}
	
	public static AccessToken getAccessToken(){
//		{"access_token":"bLMFfgtKvFj-V9S8ukGc626NVN0dGn9vj4yVRVPD4QoczoGiY8sMXBjHr4GAJRIr9t-qjFl1-aS8_nx0yvgdkf_Wuj1YWIpKedPpIErueCHHTi-00EG5-F1Co1qLtQXQxUstaAoHmObxo-1FcxJAOg","expires_in":7200}
		String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret;
		HttpResponse response = Http.get(url);
		return response.asObject(AccessToken.class);
	}
	
	public static WXHttpResult createMenus(String accessToken,String menusJSON){
		String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+accessToken;
		HttpResponse response = Http.post(url, menusJSON);
		return response.asObject(WXHttpResult.class);
	}
	
	public static WXHttpResult deleteMenus(String accessToken){
		String url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token="+accessToken;
		HttpResponse response = Http.get(url);
		return response.asObject(WXHttpResult.class);
	}
	
	public static Menu getMenus(String accessToken){
		String url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token="+accessToken;
		HttpResponse response = Http.get(url);
		return response.asObject(Menu.class);
	}
	
//	button 	是 	一级菜单数组，个数应为1~3个
//	sub_button 	否 	二级菜单数组，个数应为1~5个
//	type 	是 	菜单的响应动作类型，目前有click、view两种类型
//	name 	是 	菜单标题，不超过16个字节，子菜单不超过40个字节
//	key 	click类型必须 	菜单KEY值，用于消息接口推送，不超过128字节
//	url 	view类型必须 	网页链接，用户点击菜单可打开链接，不超过256字节 
}
